package com.test;

import android.widget.GridView;

import java.util.concurrent.*;

/**
 * @author MaTianyu @http://litesuits.com
 * @date 2015-08-11
 */
public class ThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>());

        for (int i = 0; i < 7; i++) {
            final int j = i;
            //pool.submit(new Runnable() {
            //    @Override
            //    public void run() {
            //        System.out.println(j + " : " + Thread.currentThread().getId());
            //        try {
            //            Thread.sleep(1000);
            //        } catch (InterruptedException e) {
            //            e.printStackTrace();
            //        }
            //    }
            //});
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(j + " : " + Thread.currentThread().getId());
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}
